<!-- 合同-基础设置-企业印章 -->
<template>
  <div class="base-setting">
    <pageHeaderNew :title="title" :breadCrumb="breadCrumb"></pageHeaderNew>
    <div class="wrap">
      <div class="header">
        <div>
          <a-input-search
            :style="{ width: '220px' }"
            placeholder="姓名"
            search-button
            @search="onSearch"
            @press-enter="onSearch"
            v-model="nameSearch"
          />
        </div>
        <div>
          <a-button type="outline" @click="add(null)">新增印章</a-button>
        </div>
      </div>
      <table-turn :table-data="getTableData" ref="tableRef" :args="args">
        <a-table-column :width="80">
          <template #title> 序号 </template>
          <template #cell="{ rowIndex }">
            {{ rowIndex + 1 }}
          </template>
        </a-table-column>
        <a-table-column :width="200" data-index="name" title="印章预览">
        </a-table-column>
        <a-table-column :width="200" data-index="definition" title="印章名称">
        </a-table-column>
        <a-table-column :width="200" data-index="definition" title="印章规格">
        </a-table-column>
        <a-table-column :width="200" data-index="definition" title="印章类型">
        </a-table-column>
        <a-table-column :width="200" data-index="definition" title="制造时间">
        </a-table-column>
        <a-table-column :width="200" data-index="definition" title="使用次数">
        </a-table-column>
        <a-table-column :width="200" data-index="enable" title="启用状态">
          <template #cell="{ record }">
            <a-switch
              v-model="record.enable"
              :checked-value="1"
              :unchecked-value="2"
              @change="stateChange(record)"
            ></a-switch>
          </template>
        </a-table-column>
        <a-table-column :width="200" data-index="" title="操作" fixed="right">
          <template #cell="{ record }">
            <a-tooltip content="编辑">
              <IconFont
                type="icon-edit"
                :size="26"
                :style="{
                  marginRight: '10px',
                  cursor: 'pointer'
                }"
                @click="goEdit(record)"
              />
            </a-tooltip>
            <a-tooltip content="删除" position="left">
              <a-popconfirm
                content="是否确认删除该条数据?"
                position="left"
                @ok="del(record.id)"
              >
                <icon-font
                  type="icon-delete"
                  :size="26"
                  :style="{
                    cursor: 'pointer',
                    marginRight: '10px'
                  }"
                />
              </a-popconfirm>
            </a-tooltip>
          </template>
        </a-table-column>
      </table-turn>
    </div>
  </div>
</template>

<script lang="ts" setup>
const router = useRouter();
const title = '企业印章';

const breadCrumb: string[] = ['合同', '基础设置', '企业印章'];

let modalVisible = ref(false); // 判断新增弹出框是否打开
let currData = ref(); // 储存当前选中数据
let tableRef = ref();
// 表格配置
const args = reactive({
  rowSelection: {
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false
  }
});
// 新增
const add = (record: any) => {
  router.push({
    name: 'CorporateSealAdd',
    query: {
      id: 0
    }
  });
};

// 获取表格数据
const getTableData = async () => {
  try {
    // originData.value = await GetHumanChangeSetting({
    //   typeId: 1 // 人事异动默认传1
    // });
    // const res: any = originData.value.find(
    //   (item: any) => item.id === currId.value
    // );
    // res.content = res.personnelChange;
    // return Promise.resolve(res.personnelChange);
  } catch (error: unknown) {
    console.log(error);
  }
};

// 编辑
const goEdit = (record: any) => {
  console.log(record);
  currData.value = record;
  modalVisible.value = true;
};

// 删除某一行
const del = async (id: number) => {
  try {
    // await DelHumanChangeSetting({ id });
    refresh();
  } catch (error: unknown) {
    console.log(error);
  }
};

// 弹窗自定义事件
const indexEmit = async (record: any) => {
  //
};

// 刷新表格数据
const refresh = () => {
  tableRef.value.loadData();
};
</script>

<style scoped lang="less">
.wrap {
  padding: 20px;

  .header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
  }
}
</style>
